package Test05;

import java.util.Objects;

public class Student {
    private String name;
    private int age;
    private int score;
    private  String gender;

    public Student(String name, int age, int score, String gender) {
        this.name = name;
        setAge(age);
        this.score = score;
        setGender(gender);

    }



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
      return age;

    }

    public void setAge(int age) throws AgeException {
        if (age<15||age>50){
            throw new AgeException("年龄非法，必须在15到50之间");
        }else {this.age=age;}
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) throws SexException {
      if (Objects.equals("男",gender)&&Objects.equals("女",gender)){
          throw new SexException("年龄异常");
      }else {
          this.gender=gender;
      }
    }
}
